package me.jessyan.mvparms.demo.mvp.ui.activity.shoppcard;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.xrecyclerview.XRecyclerView;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.BaseHolder;
import com.jess.arms.base.DefaultAdapter;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import me.jessyan.mvparms.demo.di.component.shoppcard.DaggerApplyStoreComponent;
import me.jessyan.mvparms.demo.di.module.shoppcard.ApplyStoreModule;
import me.jessyan.mvparms.demo.mvp.contract.shoppcard.ApplyStoreContract;
import me.jessyan.mvparms.demo.mvp.presenter.shoppcard.ApplyStorePresenter;

import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.mvp.ui.activity.car.OrderDetailActivity;
import me.jessyan.mvparms.demo.mvp.ui.activity.car.PayCostRcordActivity;
import me.jessyan.mvparms.demo.mvp.ui.adapter.PayCostRecordAdapter;
import me.jessyan.mvparms.demo.mvp.ui.widget.CustomToolbar;


import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * 适用门店
 */
public class ApplyStoreActivity extends BaseActivity<ApplyStorePresenter> implements ApplyStoreContract.View {
    @BindView(R.id.recyclerView)
    XRecyclerView recyclerView;
    @BindView(R.id.toolbar)
    CustomToolbar toolbar;
    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerApplyStoreComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .applyStoreModule(new ApplyStoreModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_apply_store; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        initRecycler();
        toolbar.setListener(new CustomToolbar.ToolbarListener() {
            @Override
            public void onLeftBack() {
                killMyself();
            }

            @Override
            public void onRightBack() {

            }
        });
    }

    /**
     * 初始化recycler
     */
    private void initRecycler() {
        List<String> list = new ArrayList<>();
        list.add("s");
        list.add("s");
        list.add("s");

        LinearLayoutManager lr = new LinearLayoutManager(getApplicationContext(),LinearLayoutManager.VERTICAL,false);
        recyclerView.setLayoutManager(lr);
        ArmsUtils.configRecyclerView(recyclerView,lr);
        recyclerView.clearHeader();
        recyclerView.setPullRefreshEnabled(false);
        DefaultAdapter adapter = new DefaultAdapter(list,true) {
            @Override
            public BaseHolder getHolder(View v, int viewType) {
                return new BaseHolder(v) {
                    @Override
                    public void setData(Object data, int position) {

                    }
                };
            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_apply_store;
            }

            @Override
            public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {

            }
        };

        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new DefaultAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int viewType, Object data, int position) {

            }
        });

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }
}
